#!/usr/bin/perl

use lib "./";
use JSON qw(jsonToObj);
use Flickr::API;
use Flickr::API::Request;

my $api = new Flickr::API({
    'key'    => 'hogefugahogesugahogefugahogesuga',
    'secret' => '123456789'
});

$api->proxy(['http', 'ftp'], 'http://proxy:8099/');

my $request = new Flickr::API::Request({
              'method' => 'flickr.photos.search',
#              'method' => 'flickr.photos.getrecent',
              'args'   => {tags=>'kitty','format'=>'json',license=>4},
      });

my $response = $api->execute_request($request);

if ( $response->is_success ) {
    my $content = $response->content;
    $content =~ s/jsonFlickrApi\((.+?)\)$/$1/;
    my $obj = jsonToObj($content);
    for(@{$obj->{photos}->{photo}}){
        $url = 'http://farm'.$_->{farm}.'.static.flickr.com/'.$_->{server}.'/'.$_->{id}.'_'.$_->{secret}.'.jpg';
        print "$url \n";
        #system "wget $url";
        ### wrote.
        #sleep 3;
    }
}

__END__

